var app=getApp();

Page({


    formSubmit:function(e){
        if (e.detail.value.user_name.length == 0 || e.detail.value.password==0){
            wx.showModal({
                title: '手机号码或密码不得为空',
                showCancel: false,
                duration:1500
            })
        }else if(e.detail.value.user_name.length!=11){
            wx.showModal({
                title: '请输入11位手机号码',
                showCancel: false,
                duration:2000
            })

        }else{

            var that = this;  
            var formData = e.detail.value; 
            var baseUrl = app.url;
            
            wx.login({
            success: function (res) {
               if (res.code) {
                    formData['code'] = res.code;
                    //发起网络请求
                    wx.request({
                        url:baseUrl +'/login/login',
                        method: 'POST',
                        data: formData,
                        header: {
                           'Content-Type': 'application/json'
                        }, 
                        success: function (res) {
                            switch (res.data.code) {
                                case 1:
                                    wx.setStorageSync("PHPSESSID",res.data.data.PHPSESSID);
                                    wx.setStorageSync("nodes",res.data.data.nodes);  
                                        wx.reLaunch({
                                          url: '../index/index'
                                        })
                                                                               
                                    break;
                                case 10001:
                                     console.log(res.data);
                                     wx.showModal({
                                        content: '登录失败,请重新登陆',
                                        showCancel: false,
                                        
                                    }); 
                            
                                    break;
                                 case 10002:
                                    console.log(res.data.msg);
                                    wx.showModal({
                                        content: '账号密码错误,请重新登陆',
                                        showCancel: false,
                                        
                                    }); 
                                    break;    
                                    default:
                                    console.log(res);
                                    break;
                            }        
                        },
                    });
                } else {
                    console.log('获取用户登录态失败！' + res.errMsg)
                }
            }
       });
       

  }
}
  
})